
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page import="java.util.ArrayList,
                 com.scalar.chiptrack.users.User,
                 com.scalar.chiptrack.users.Functionality,
                 com.scalar.chiptrack.users.dao.UserDAO,
                 com.scalar.chiptrack.utils.ConfigManager"%>

<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean" %>
<%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ taglib uri="/WEB-INF/chiptrack-tags.tld" prefix="chiptrack" %>

<chiptrack:checkLogon sourcePage="/maintainUser.do"/>

<html:html locale="true">

<%String chipTracContext = "/" + ConfigManager.getChipTracContext();%>

<HEAD><TITLE>Scalarsoft - ChipTrac</TITLE>
<META http-equiv=Content-Type content="text/html; charset=windows-1252">
<LINK href="<%=chipTracContext%>/jsp/includes/stylesheets/scalarsoft.css" type=text/css rel=stylesheet>

<script language='javascript'>
function search() {
    //if( validate() )
    document.maintainUserForm.submit();
}
function reset(){
    document.maintainUserForm.reset();
}
function validate()
{
    var form = document.maintainUserForm;
	var pa=document.getElementById("message");
	pa.innerHTML='';
    var fName = document.maintainUserForm.firstName.value;
    var lName = document.maintainUserForm.lastName.value;
    var groupName = document.maintainUserForm.groupName.value;
    var userListSize = document.maintainUserForm.userList.value;
    //alert("userList :"+userListSize);
    if( fName != '')
    {
        if( groupName == '-1')
        {
            pa.innerHTML = "<li>Please Select Group Name";
            document.maintainUserForm.groupName.focus();
            return false;
        }
        else if( userListSize == '0' )
        {
            pa.innerHTML = "<li>Users: Not found with this search";
            document.maintainUserForm.firstName.focus();
            return false;
        }
        else
        {
            return true;
        }
    }
    else if( lName != '')
    {
        if( groupName == '-1')
        {
            pa.innerHTML = "<li>Please Select Group Name";
            document.maintainUserForm.groupName.focus();
            return false;
        }
        else if( userListSize == '0' )
        {
            pa.innerHTML = "<li>Users: Not found with this search";
            document.maintainUserForm.firstName.focus();
            return false;
        }
        else
        {
            return true;
        }
    }
    else if( userListSize == '0' )
    {
        pa.innerHTML = "<li>Users: Not found with this search";
        document.maintainUserForm.firstName.focus();
        return false;
    }
    else
    {
        return true;
    }
}
</script>

<META content="MSHTML 5.50.4807.2300" name=GENERATOR></HEAD>
<BODY bgColor='#ffffff' leftMargin=0 topMargin=0 marginheight="0" marginwidth="0">

<!-- Top Header Start-->
<%@ include file="/jsp/includes/header.jsp" %>
<!-- Top Header End-->

<TABLE cellSpacing=0 cellPadding=0 width="100%" border=0>
  <TBODY>
  <TR>
	<td width='180' valign='top' background='<%=chipTracContext%>/jsp/includes/images/left_red_bg.gif'>

<!-- Side Navigation start -->
<%@ include file="/jsp/admin/admin_menu.jsp" %>
<!-- end of the side navigations -->

<TD bgcolor="#ffffff">
<IMG height=9 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=8></TD>
<TD bgcolor="#ffffff"><IMG height=480 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=2></TD>
<TD valign="top" width="100%">

<IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/clear.gif" width=500 border=0>
<BR>



<!-- from here your body starts -->

<html:form name="maintainUserForm" type="com.scalar.chiptrack.users.forms.MaintainUserForm" action="/maintainUser">


<center><span class="NArialW">Maintain Users</span></center>
<img src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=20>
<table border="0" width="90%" align=right>
 <tr><td>

<chiptrack:errors styleClass='NArialL' />
<chiptrack:info styleClass='NArialL' />

 <table border="0" width="50%" cellspacing='10' cellpadding='2' align='left'>
     <tr><td colspan = '4' Class="NArialL"><FONT color='FF0000' id="message" > </font></td></tr>
	<tr>
        <%--<td colspan='2' nowrap><font class="NArialL">First Name:&nbsp;&nbsp;</font>
			<input type="text" name="firstName" size="25" maxlength="25" class="txfield">
		</td>
        <td colspan='2' nowrap><font class="NArialL">Last Name:&nbsp;&nbsp;</font>
	        <input type="text" name="lastName" size="25" maxlength="25" class="txfield">
        </td>--%>
        <td colspan='2' nowrap><font class="NArialL">First Name:&nbsp;&nbsp;</font>
			<html:text name="maintainUserForm" property="firstName" size="25" maxlength="25" styleClass="txfield" />
		</td>
        <td colspan='2' nowrap><font class="NArialL">Last Name:&nbsp;&nbsp;</font>
	        <html:text name="maintainUserForm" property="lastName" size="25" maxlength="25" styleClass="txfield" />
        </td>

    </tr>
    <tr>
        <td colspan='2' nowrap><font class="NArialL">Group:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</font>
            <html:select name="maintainUserForm" property="groupName" styleClass="txfield" >
                <html:option value="-1">- Select group Name -</html:option>
                <html:options collection="groupList" property="name"/>
            </html:select>
	    </td>
    </tr>
	<tr>
        <td colspan='2' nowrap align='right'>
		     <a href="javascript:search()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/search.gif" width="53" height="17" onMouseOver="window.status='Click to Search for User';return true" onMouseout="window.status='';return true" title="Click here to Search for User"></a>
	    </td>
		<td colspan='2' nowrap align='left'>
		     <a href="javascript:reset()"><img border="0" src="<%=chipTracContext%>/jsp/includes/images/reset.gif" width="53" height="17" onMouseOver="window.status='Click to Reset';return true" onMouseout="window.status='';return true" title="Click here to Reset"></a>
	    </td>
    </tr>
    <tr>
    <td align='right' valign='center' width='3%'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/exclamation-46x47.gif" width="24" height="24" align='center'></td>
    <td align='left' valign='center' nowrap><font class="NArialS">Blank fields defaults to 'All'</font></td>
    </tr>


  </table>


  </td></tr>
  <tr><td><img height=10 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif"></td></tr><tr><td>


<!-- DISPLAY ALL USERS STARTS HERE -->

<%
	ArrayList userList = (ArrayList) session.getAttribute ("userList");
	if (userList == null) userList = new ArrayList();
	if(userList.size()==0){
%>
  <font class="NArialL"><font color="FF0000"><li>Users: Not found with this search </font></font></td></tr>
  <%
	}else{
  %>

<table border="0" width="100%" bordercolor="#FFFFFF" align=right>
    <tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=10></td></tr>

    <tr>
    <td align='right' valign='center' width='2%'><img border="0" src="<%=chipTracContext%>/jsp/includes/images/exclamation-46x47.gif" width="24" height="24" align='center'></td>
    <td align='left' valign='center' nowrap colspan='4'><font class="NArialS">User Names that are in <font color='red'>Red</font> are disabled, and <font color='orange'>Orange</font> are expired</font></td>
    </tr>

    <tr>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">User Name</font></td>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">User ID</font></td>
        <td width="15%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Group</font></td>
        <td width="40%" align="center" bgcolor="#993333"><font class="NArialL"><font color="#FFFFFF">Actions</font></font></td>
        <td width="15%">&nbsp;</td>
    </tr>

        <%
            User userobj = null;
            int userListSize = userList.size();

            for (int i=0; i<userListSize; i++) {

                userobj = (User) userList.get (i);
        %>
            <tr>
                <td nowrap width="15%" align="left" <%if (i%2 == 0) out.print ("bgcolor='#DEE1E2'");%>><font class="NArialL">
                    <%
                        if (userobj.getDisabled() == true) {
                            out.println ("<font color='red'>"); 
                        }
                        else if (userobj.isExpired() == true) {
                            out.println ("<font color='orange'>"); 
                        }
                        else {
                            out.println ("<font color='black'>");
                        }
                    %>
                    &nbsp;&nbsp;<%=userobj.getFirstName()%>&nbsp;<%=userobj.getLastName()%></font></font>
                </td>

                <td nowrap width="15%" align="left" <%if (i%2 == 0) out.print ("bgcolor='#DEE1E2'");%>><font class="NArialL">
                    &nbsp;&nbsp;<%=userobj.getUserId()%></font></font>
                </td>

                <td nowrap width="15%" align="left" <%if (i%2 == 0) out.print ("bgcolor='#DEE1E2'");%>><font class="NArialL">
                    &nbsp;&nbsp;<%=userobj.getGroupName()%></font>
                </td>

                <td nowrap width="40%" align="center" <%if (i%2 == 0) out.print ("bgcolor='#DEE1E2'");%>>

		    <table width=100%>
			<tr>

			    <td width=30% align=center>
			        <font class="NArialL"><chiptrack:restrictedLink functionality='<%=Functionality.MAINTAIN_USERS%>' action='<%=User.USER_ACTION_VIEW%>' href='<%="/chiptrack/jsp/admin/user_setup.jsp?useraction=view&username=" + userobj.getUserId()%>' onmouseover="window.status='Click to View User Information';return true" onmouseout="window.status='';return true">View </chiptrack:restrictedLink></font>
			    </td>

			    <td width=30% align=center>
			        <font class="NArialL">
                    <%if(userobj.getDisabled() == false) {%>
                    <chiptrack:restrictedLink functionality='<%=Functionality.MAINTAIN_USERS%>' action='<%=User.USER_ACTION_MODIFY%>' href='<%="/chiptrack/jsp/admin/user_setup.jsp?useraction=modify&username=" + userobj.getUserId()%>' onmouseover="window.status='Click to Modify User Information';return true" onmouseout="window.status='';return true">Modify</chiptrack:restrictedLink></font>
                    <%}else{%>
                      <chiptrack:restrictedLink functionality='' action='<%=User.USER_ACTION_MODIFY%>' href=""  onmouseover="window.status='Click to Modify User Information';return true" onmouseout="window.status='';return true"><font color="red">Modify</font></chiptrack:restrictedLink></font>
                    <%}%>

			    </td>

			    <td width=30% align=center>
				<font class="NArialL">
                    			<%if ( !userobj.isExpired() && userobj.getDisabled() == false) {%>
		                    	<chiptrack:restrictedLink functionality='<%=Functionality.MAINTAIN_USERS%>' action='<%=User.USER_ACTION_DELETE%>' href='<%="/chiptrack/maintainUser.do?useraction=delete&username=" + userobj.getUserId()%>' onmouseover="window.status='Click to Disable User';return true" onmouseout="window.status='';return true">Disable</chiptrack:restrictedLink>
                    			<%} else if (userobj.getDisabled() == true) {%>
                    			<chiptrack:restrictedLink functionality='<%=Functionality.MAINTAIN_USERS%>' action='<%=User.USER_ACTION_DELETE%>' href='<%="/chiptrack/maintainUser.do?useraction=activate&username=" + userobj.getUserId()%>' onmouseover="window.status='Click to Activate User';return true" onmouseout="window.status='';return true"><font color="red">Activate</font></chiptrack:restrictedLink>
                    			<%}%>
				</font>
			    </td>

			</tr>
		    </table>
                </td>

                <td width="15%">&nbsp;</td>
            </tr>

        <%
            }
        %>

    <tr><td class="NArialL" colspan=5><IMG src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" height=50></td></tr>
</table>
<%}%>
<!-- DISPLAY ALL USERS ENDS HERE -->

</td></tr>
</table>
<%-- <input type = "hidden" name = "userList" value = '<%= userList.size()%>' >--%>
</html:form>

<!-- till here -->
<BR><BR><BR></TD>
<TD bgcolor="#ffffff"><IMG height=1 src="<%=chipTracContext%>/jsp/includes/images/spacer.gif" width=1></TD>
</TR>
</TABLE>

<!-- Footer starts here -->
<%@ include file="/jsp/includes/footer.jsp" %>
<!-- footer end here -->

</body>

</html:html>